package com.cn.gmall.order.config;

import ch.qos.logback.classic.turbo.TurboFilter;
import com.cn.gmall.common.mqconst.MqConst;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.ClusterInfo;

import java.util.HashMap;

@Configuration
public class OrderCancelMqConfig {
    @Bean
    public Queue cancelQueue() {
//        队列
        return new Queue(MqConst.QUEUE_ORDER_CANCEL, true);
    }
    @Bean
    public CustomExchange cancelExchange(){  //延时交换机
        HashMap<String, Object> arguments = new HashMap<>(); // 参数
        arguments.put("x-delayed-type", "direct");
        return  new CustomExchange(MqConst.EXCHANGE_DIRECT_ORDER_CANCEL,"x-delayed-message", true,false,arguments);
    }

    @Bean
    public Binding bindingDelay(){
//        用路由 绑定交换机 和队列
        return BindingBuilder.bind(cancelQueue()).to(cancelExchange()).with(MqConst.ROUTING_ORDER_CANCEL).noargs();
    }

}
